package com.example.echoewish.custom_compose;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.example.echoewish.R;

public class TitleBar extends RelativeLayout {
    private int color=R.color.normal;
    private String[] titles={"帖子详情页","登录","注册","我的发布","我的回复","我的消息","个人主页","资料修改","我的好友","好友请求","聊天记录","bug"};
    private String title="首页";

    public TitleBar(Context context) {
        super(context);
        initiView(context);
    }

    public TitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);

        title = titles[attrs.getAttributeIntValue(null, "text", 2)];;
        initiView(context);
    }

    public TitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initiView(context);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public TitleBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initiView(context);
    }

    public void initiView(Context context)
    {
        LayoutInflater.from(context).inflate(R.layout.layout_titlebar,this);

        TextView titleTextView=findViewById(R.id.text_title);
        Button titleBack = (Button) findViewById(R.id.button_backward);
        titleTextView.setText(title);
        titleBack.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                ((Activity) getContext()).finish();
            }
        });
    }
}
